package com.bobo.web.provider.util.commutils;

import com.google.common.collect.Maps;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

/**
 * @author pangchuanxiao@qiyi.com
 *         Created on 2014/12/10 in project floo-apps.
 */
public interface RestTemplatePools {

    RestTemplate make(int readTime);

    static class Impl implements RestTemplatePools {
        private static RestTemplatePools impl = new Impl();
        private Map<Integer, RestTemplate> map;
        private Impl() {
            map = Maps.newConcurrentMap();
        }
        public static RestTemplatePools getInstance() {
            return impl;
        }
        @Override
        public RestTemplate make(int readTime) {
            if (map.containsKey(readTime)) {
                return map.get(readTime);
            }
            RestTemplate restTemplate = RestTemplateFactory.getTemplate(readTime);
            map.put(readTime, restTemplate);
            return restTemplate;
        }
    }
}
